/* file : connect_msg.c
 * define connector message handler
 *
 * author : neil duan
 * all right reserved 2009
 * 2009-2-21 14:30
 */

#include "nd_cliapp/nd_cliapp.h"
extern NDINT32 loging_message_handle(nd_handle nethandle,nd_usermsgbuf_t *recv_msg, nd_handle h_listen) ;



NDINT32 test_message_handle(nd_handle nethandle,nd_usermsgbuf_t *recv_msg, nd_handle h_listen) 
{
	NDINT8 tmp ;
	NDINT32 len = ND_USERMSG_LEN(recv_msg) - ND_USERMSG_HDRLEN;
	NDINT8 *addr = ND_USERMSG_DATA(recv_msg) ;
	tmp = addr[len] ;
	addr[len] = 0 ;
	ndprintf("[TEST MSG maxid=%d minid=%d] %s\n", ND_USERMSG_MAXID(recv_msg),ND_USERMSG_MINID(recv_msg), addr) ;
	addr[len] = tmp ;
	return 0 ;

}

void install_msg(nd_handle connector)
{
	NDINT32 i;
	for (i=0; i<SSM_MSG_NUM; i++)
	{
		//install_climsg_entry(loging_message_handle, MAXID_START_SESSION, i, 0);
		nd_msgentry_install(connector,(nd_usermsg_func)loging_message_handle, MAXID_START_SESSION, i, 0);
	}
	nd_msgentry_install(connector,(nd_usermsg_func)test_message_handle, MAXID_SYS, SYM_TEST, 0);
}

NDINT32 test_broadcast_handle(nd_handle nethandle,nd_usermsgbuf_t *recv_msg, nd_handle h_listen) 
{
	NDINT8 tmp ;
	NDINT32 len = ND_USERMSG_LEN(recv_msg) - ND_USERMSG_HDRLEN;
	NDINT8 *addr = ND_USERMSG_DATA(recv_msg) ;
	tmp = addr[len] ;
	addr[len] = 0 ;
//	ndprintf("[BROADCAST MSG maxid=%d minid=%d] %s\n", ND_USERMSG_MAXID(recv_msg),ND_USERMSG_MINID(recv_msg), addr) ;
	addr[len] = tmp ;
	return 0 ;

}
